<template>
    <div class="myQuitDialog" >
        <el-dialog v-model="ifToCloseWindow" title="退出设置" class="dialog">
            <div class="choice">
                <span>点击关闭按钮时，你希望</span>
                <el-radio-group v-model="choiceW">
                    <el-radio label="leave" size="large">最小化到托盘</el-radio>
                    <el-radio label="quit" size="large">退出程序</el-radio>
                </el-radio-group>
                <el-checkbox v-model="ifNever" label="不在提醒" size="large" />
            </div>
            <template #footer>
                <span class="dialog-footer">
                    <el-button class="left" @click="giveUp">取消</el-button>
                    <el-button class="right" @click="toCloseOrSmall" type="primary">确定</el-button>
                </span>
            </template>
        </el-dialog>
    </div>
</template>

<script setup lang="ts">
import { getActivePinia } from 'pinia';
import { Ref, ref, reactive,watch,toRef } from 'vue'
import {useElectronToApp} from '../store'

const ElectronToApp = useElectronToApp();


let choiceW: Ref<string> = ref('leave')
let ifNever: Ref<boolean> = ref(false)
let ifToCloseWindow:Ref<boolean> = toRef(ElectronToApp,'ifToCloseWindow')

const giveUp = ():void =>{
    ifToCloseWindow.value = false;
    ElectronToApp.$patch({ifToCloseWindow:false})
}

const toCloseOrSmall = ()=>{
    //发送选择情况
    ifToCloseWindow.value = false
    if(ifNever.value){
        localStorage.setItem('XWay',choiceW.value)
    }
    let t = setTimeout(()=>{
        electronIpc.ipcInvoke('to-close-or-small',choiceW.value) 
        clearTimeout(t)
    },100)
}

</script>

<style lang="less" scoped>
:deep(.is-checked) {

    .el-radio__label,
    .el-checkbox__label {
        color: @primary-color !important;
    }

    .el-radio__inner,
    .el-checkbox__inner {
        background-color: @primary-color !important;
        border-color: @primary-color !important;
    }
}

.myQuitDialog {
    user-select: none;
    color:@font-color;
    width: 100%;
    height: 100%;
    :deep(.el-dialog) {
        min-width: 600px;
        max-width: 40vw;
        min-height: 400px;
        background-color: @mianban-bk-color;
        .el-dialog__header{
            >span{
                color: @font-color;
            }
        }
    }
    :deep(.el-dialog){
        min-width: 500px;
        max-width: 500px;
    }
    .choice {
        display: flex;
        flex-direction: column;
        flex-wrap: wrap;
        width: 70%;
        margin: 0 auto;

        &>* {
            padding-top: 20px;
        }

        span {
            font-size: 22px;
            color: @font-color;
        }

        .el-radio-group {
            .el-radio {
                font-size: 20px !important;
                color: @font-color;

                :deep(.el-radio__inner) {
                    height: 20px;
                    width: 20px;

                    &:hover {
                        border-color: @primary-color;
                    }

                    &::after {
                        height: 8px;
                        width: 8px;
                    }
                }

                :deep(.el-radio__label) {
                    font-size: 18px;
                }
            }
        }

        .el-checkbox {
            color: @font-color;

            :deep(.el-checkbox__inner) {
                height: 20px;
                width: 20px;

                &:hover {
                    border-color: @primary-color;
                }

                &::after {
                    border: 2px solid var(--el-checkbox-checked-icon-color);
                    height: 13px;
                    left: 7px;
                    border-left: 0;
                    border-top: 0;
                }
            }

            :deep(.el-checkbox__label) {
                font-size: 20px !important;
            }
        }

    }
    :deep(.el-dialog__footer){
        display: flex;
        justify-content: center;
        :deep(.dialog-footer){
            display: inline-block;
            margin: 0 auto;
        }
        .el-button{
            width: 150px;
            height: 40px;
            border: none;
        }
        .left{
            background-color: #eff1f2;
            color:black;
            &:hover{
                background-color: #e3e5e6;
            }
        }
        .right{
            background-color: @primary-color;
        }
    }

}
</style>